feat: support locally provided CLI binaries via binaryDestination#286
feat: support locally provided CLI binaries via binaryDestination#286
Conversation
Reimplemented `binPath` to support three modes: - default data directory - absolute path to a pre-existing local CLI (when downloads are disabled) - and base directory with host-specific subdirectory (when downloads are enabled) This modes are controlled by the Binary directory setting now renamed to Binary destination and the enable downloads setting. - resolves #285
That tests the fallback configuration from binaryDestination to the deprecated binaryDirectory. In addition, the existing tests were updated as they now have to take into account that enableDownloads option affects the output of binPath API.
Windows needs special handling because we can't mock the exe binary as a bash script like we do on Linux/Mac. In addition, there were a couple of unix paths hardcoded in some of the tests.
src/main/kotlin/com/coder/toolbox/settings/ReadOnlyCoderSettings.kt
Outdated
Show resolved
Hide resolved
Windows needs special handling because we can't mock the exe binary as a bash script like we do on Linux/Mac. In addition, there were a couple of unix paths hardcoded in some of the tests.
binaryDestination can now take a path to an executable or a path to a download directory.
In order to reflect the new behavior regarding CLI resolution in general and the binary destination in particular.
Adds a chapter describing the behavior of binaryDestination, dataDir, enableDownloads, and enableBinaryDirFallback, and explains how these settings interact and work together.
Refactored some of the existing tests into a new battery with a bunch additional tests to cover the complex and intertwined way of working for binaryDestination, enableDownloads, dataDir and enableFallback settings in the way CLI is resolved.
Without GIT bash utilities installed. To remove the dependency I duplicated some of the tests and used Windows commands only.
|
I'm a bit confused by the That's the whole thing. No I think trying to have |
You are absolutely right. The complexity explodes due to so many controlling flags and options and combinations of them. Now I don't have the full context but it seems like all of these were dragged from the Gateway support. I'll have to dig up the git history and understand the context around why all of them were needed. Now to your point I think |
|
I think the data dir fallback was not explicitly requested by any customer. Someone asked for the ability to customize the binary path to a location only the sysadmin could write to, and the setting would also be controlled by the admin, and I think the logic was "well if that binary is bad or missing or out of date we want to be able to still fall back and download a working binary". But I am not sure anyone relies on that behavior. One problem is, if sysadmins are doing this, usually it is because unauthorized binaries are not allowed to run on the system anyway. So this fallback would not work in any case. Possibly we can safely remove it without affecting anyone. But yeah we still need |
|
There is no support in Toolbox but I think we can write our own migration support for these settings. So that should ease out some of the concerns if it ever gets to the point where we decide to simplify. More or less to me it looks like VS Code extension still relies on two paths just that it cascades automatically without the complication of "enable fallback" which BTW is restricted ONLY to access denied errors. |
Yes that is my only concern tbh, if Two small things I noticed:
Everything else looks good to me and I like the much improved version here! Test coverage is solid and the docs are clear! |
This is what happens for any other type of issue. But not in the case access denied exceptions. I'll talk to Atif and see if can get greenlight to simplify this. I tracked down the original change and Asher was right, it was not requested by anyone.
|
lol I seem to have predicted the future in that PR:
|
| - `Enable binary directory fallback` when enabled, if the binary destination is not writable the | ||
| plugin falls back to the data directory instead of failing. Only takes effect when downloads are | ||
| enabled and the binary destination differs from the data directory. Defaults to disabled. |
There was a problem hiding this comment.
Just an observation, but if we end up having to keep support for the fallback, then we might consider making this option also affect when downloads are disabled, so admins have the ability to always force using the configured binary even if a user places their own more up-to-date binary in their data directory.
If we can remove the fallback though then this disappears anyway.
And use the correct key, instead of the deprecated one.
|
Not a blocker but would it make sense that if the Of course people can just point to the binary and that would work but yeah |
I'm simply afraid of the danger of overwriting a manually downloaded CLI when the version no longer matches. Maybe instead we could check (in the order of priority):
But then it feels like once again we overengineer the CLI resolution 🤔 |
Def agree with this. I do still kind of wish we could make a brand new setting with placeholders (defaults to |
This PR is a result of discussion that happened in the #286. Basically it as an attempt of simplifying the CLI resolution and trying to be more aligned with the VS Code extension. The existing implementation was too cumbersome to understand, brittle and a lot of tedious work needed to solve all of it's usecases. This PR removes the enable fallback to data dir setting, which was used only for access denied exceptions. The CLI resolution uses the binary destination if it was configured by the user, or it automatically falls back to data dir if binary destination was not configured. The implementation respects the user's choice and no longer tries to make smart choices on behalf of the user. For example if the user configured the binary destination but disabled downloads we just prompt him with an error instead of trying to fall on data dir. There were a couple of other small improvements left from the previous PR that are now addressed. - resolves #285
The existing CLI resolution logic hardcodes the CLI name based on the OS and architecture without any flexibility in specifying an existing CLI. It has a couple of options to specify the download dir (binDir and dataDir) but not the CLI name. This PR revolves around the bindDir setting which is now renamed to binaryDestination and it allows users to specify an absolute path to an existing executable filename or a destination dir. If the user specifies the destination dir then the CLI name will use the existing default name based on the os and architecture.
In addition a couple of windows tests were refactored because they required git bash utilities to be installed on Windows. Recent builds on the Github CI failed because commands like
printfwere not available.A lot of UTs were also added to cover the behavior of CLI resolution when based on how binaryDestination, dataDir, enableDownloads and enableFallback flags are configured. Now there is also a special section in the README detailing the CLI resolution algorithm.
By and large we tried to keep the existing behavior without breaking compatibility for existing users who were supposed to configure a folder in the binaryDir.
The new behavior works like this: